package com.peanut.web.controller;

import java.util.Random;

import javax.servlet.http.HttpServletRequest;

import com.peanut.web.util.ocs.OCSCacheWebUtil;

/**
 * 基础 controller
 * 
 * @author songjz
 */
public class BaseController {

  /**
   * 设置验证码 到缓存中
   * 
   * @param bzPrefix
   *          业务类型前缀
   * @return：生成的验证码
   */
  protected String setVerificationcode(String bzPrefix, HttpServletRequest request) {
    int min = 100000, max = 999999;
    Random random = new Random();
    String code = Integer.toString(random.nextInt((max - min) + 1) + min);
    OCSCacheWebUtil.cacheVerificationCode(code, bzPrefix, request);
    return code;
  }

  /**
   * 从缓存中获得用户ID
   * 
   * @param request
   * @return User
   * @throws
   */
  protected Long getCurrentUserId(HttpServletRequest request) {
    return 2l;
  }

}
